import { defineStore } from 'pinia'

export const userStore = defineStore('user', {
  state: () => ({
    userInfo: {
      name: null,
      address: null,
      phone: null,
      dietPreference: null,
      membershipLevel: null,
      redEnvelopes: null
    },
    isLoggedIn: false
  }),
  actions: {
    saveUser(user) {
      this.userInfo = {
        ...this.userInfo,
        ...user
      }
      this.isLoggedIn = true
    },
    logout() {
      this.userInfo = {
        name: null,
        address: null,
        phone: null,
        dietPreference: null,
        membershipLevel: null,
        redEnvelopes: null
      }
      this.isLoggedIn = false
    }
  },
  getters: {
    getUserInfo: (state) => state.userInfo,
    getLoginStatus: (state) => state.isLoggedIn
  }
})